// 高阶函数map

/**
 * map返回修改后的值
 * @param {Arry} ary 
 * @param {Function} fn 
 */
const map = (ary, fn) => {
  let arry = [];
  for (let item of ary) {
    arry.push(fn(item));
  }
  return arry;
}

let list = [3, 4, 5, 6, 7];

console.log(map(list, v => v * v))

/**
 * every是否都满足指定条件
 * @param {Arry} ary 
 * @param {Function} fn 
 */
const every = (ary, fn) => {
  let result = true;
  for (let item of ary) {
    result = fn(item);
    if (!result) break;
  }
  return result;
}

console.log('every', every(list, v => v > 3));

/**
 * some是否有元素满足指定条件
 * @param {Arry} ary 
 * @param {Function} fn 
 */
const some = (ary, fn) => {
  let result = false;
  for (let item of ary) {
    result = fn(item);
    if (result) break;
  }
  return result;
}

console.log('some:', some(list, v => v > 7));